using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
	/// <summary>
	/// Strongly-typed collection for the Saledetail class.
	/// </summary>
    [Serializable]
	public partial class SaledetailCollection : ActiveList<Saledetail, SaledetailCollection>
	{	   
		public SaledetailCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>SaledetailCollection</returns>
		public SaledetailCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Saledetail o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the Saledetail table.
	/// </summary>
	[Serializable]
	public partial class Saledetail : ActiveRecord<Saledetail>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Saledetail()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Saledetail(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Saledetail(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Saledetail(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Saledetail", TableType.Table, DataService.GetInstance("BookShop"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int32;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarSaleID = new TableSchema.TableColumn(schema);
				colvarSaleID.ColumnName = "SaleID";
				colvarSaleID.DataType = DbType.AnsiStringFixedLength;
				colvarSaleID.MaxLength = 15;
				colvarSaleID.AutoIncrement = false;
				colvarSaleID.IsNullable = false;
				colvarSaleID.IsPrimaryKey = false;
				colvarSaleID.IsForeignKey = true;
				colvarSaleID.IsReadOnly = false;
				colvarSaleID.DefaultSetting = @"";
				
					colvarSaleID.ForeignKeyTableName = "Sale";
				schema.Columns.Add(colvarSaleID);
				
				TableSchema.TableColumn colvarIsbn = new TableSchema.TableColumn(schema);
				colvarIsbn.ColumnName = "ISBN";
				colvarIsbn.DataType = DbType.AnsiStringFixedLength;
				colvarIsbn.MaxLength = 20;
				colvarIsbn.AutoIncrement = false;
				colvarIsbn.IsNullable = false;
				colvarIsbn.IsPrimaryKey = false;
				colvarIsbn.IsForeignKey = true;
				colvarIsbn.IsReadOnly = false;
				colvarIsbn.DefaultSetting = @"";
				
					colvarIsbn.ForeignKeyTableName = "Book";
				schema.Columns.Add(colvarIsbn);
				
				TableSchema.TableColumn colvarSellingPrice = new TableSchema.TableColumn(schema);
				colvarSellingPrice.ColumnName = "SellingPrice";
				colvarSellingPrice.DataType = DbType.Currency;
				colvarSellingPrice.MaxLength = 0;
				colvarSellingPrice.AutoIncrement = false;
				colvarSellingPrice.IsNullable = true;
				colvarSellingPrice.IsPrimaryKey = false;
				colvarSellingPrice.IsForeignKey = false;
				colvarSellingPrice.IsReadOnly = false;
				colvarSellingPrice.DefaultSetting = @"";
				colvarSellingPrice.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSellingPrice);
				
				TableSchema.TableColumn colvarAmount = new TableSchema.TableColumn(schema);
				colvarAmount.ColumnName = "Amount";
				colvarAmount.DataType = DbType.Int32;
				colvarAmount.MaxLength = 0;
				colvarAmount.AutoIncrement = false;
				colvarAmount.IsNullable = true;
				colvarAmount.IsPrimaryKey = false;
				colvarAmount.IsForeignKey = false;
				colvarAmount.IsReadOnly = false;
				colvarAmount.DefaultSetting = @"";
				colvarAmount.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAmount);
				
				TableSchema.TableColumn colvarBookType = new TableSchema.TableColumn(schema);
				colvarBookType.ColumnName = "BookType";
				colvarBookType.DataType = DbType.AnsiStringFixedLength;
				colvarBookType.MaxLength = 10;
				colvarBookType.AutoIncrement = false;
				colvarBookType.IsNullable = true;
				colvarBookType.IsPrimaryKey = false;
				colvarBookType.IsForeignKey = false;
				colvarBookType.IsReadOnly = false;
				colvarBookType.DefaultSetting = @"";
				colvarBookType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBookType);
				
				TableSchema.TableColumn colvarDiscount = new TableSchema.TableColumn(schema);
				colvarDiscount.ColumnName = "Discount";
				colvarDiscount.DataType = DbType.Double;
				colvarDiscount.MaxLength = 0;
				colvarDiscount.AutoIncrement = false;
				colvarDiscount.IsNullable = true;
				colvarDiscount.IsPrimaryKey = false;
				colvarDiscount.IsForeignKey = false;
				colvarDiscount.IsReadOnly = false;
				colvarDiscount.DefaultSetting = @"";
				colvarDiscount.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDiscount);
				
				TableSchema.TableColumn colvarWarehouseID = new TableSchema.TableColumn(schema);
				colvarWarehouseID.ColumnName = "WarehouseID";
				colvarWarehouseID.DataType = DbType.AnsiStringFixedLength;
				colvarWarehouseID.MaxLength = 10;
				colvarWarehouseID.AutoIncrement = false;
				colvarWarehouseID.IsNullable = true;
				colvarWarehouseID.IsPrimaryKey = false;
				colvarWarehouseID.IsForeignKey = true;
				colvarWarehouseID.IsReadOnly = false;
				colvarWarehouseID.DefaultSetting = @"";
				
					colvarWarehouseID.ForeignKeyTableName = "Warehouse";
				schema.Columns.Add(colvarWarehouseID);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["BookShop"].AddSchema("Saledetail",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public int Id 
		{
			get { return GetColumnValue<int>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("SaleID")]
		[Bindable(true)]
		public string SaleID 
		{
			get { return GetColumnValue<string>(Columns.SaleID); }
			set { SetColumnValue(Columns.SaleID, value); }
		}
		  
		[XmlAttribute("Isbn")]
		[Bindable(true)]
		public string Isbn 
		{
			get { return GetColumnValue<string>(Columns.Isbn); }
			set { SetColumnValue(Columns.Isbn, value); }
		}
		  
		[XmlAttribute("SellingPrice")]
		[Bindable(true)]
		public decimal? SellingPrice 
		{
			get { return GetColumnValue<decimal?>(Columns.SellingPrice); }
			set { SetColumnValue(Columns.SellingPrice, value); }
		}
		  
		[XmlAttribute("Amount")]
		[Bindable(true)]
		public int? Amount 
		{
			get { return GetColumnValue<int?>(Columns.Amount); }
			set { SetColumnValue(Columns.Amount, value); }
		}
		  
		[XmlAttribute("BookType")]
		[Bindable(true)]
		public string BookType 
		{
			get { return GetColumnValue<string>(Columns.BookType); }
			set { SetColumnValue(Columns.BookType, value); }
		}
		  
		[XmlAttribute("Discount")]
		[Bindable(true)]
		public double? Discount 
		{
			get { return GetColumnValue<double?>(Columns.Discount); }
			set { SetColumnValue(Columns.Discount, value); }
		}
		  
		[XmlAttribute("WarehouseID")]
		[Bindable(true)]
		public string WarehouseID 
		{
			get { return GetColumnValue<string>(Columns.WarehouseID); }
			set { SetColumnValue(Columns.WarehouseID, value); }
		}
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Book ActiveRecord object related to this Saledetail
		/// 
		/// </summary>
		public BookShop.Book Book
		{
			get { return BookShop.Book.FetchByID(this.Isbn); }
			set { SetColumnValue("ISBN", value.Isbn); }
		}
		
		
		/// <summary>
		/// Returns a Sale ActiveRecord object related to this Saledetail
		/// 
		/// </summary>
		public BookShop.Sale Sale
		{
			get { return BookShop.Sale.FetchByID(this.SaleID); }
			set { SetColumnValue("SaleID", value.SaleID); }
		}
		
		
		/// <summary>
		/// Returns a Warehouse ActiveRecord object related to this Saledetail
		/// 
		/// </summary>
		public BookShop.Warehouse Warehouse
		{
			get { return BookShop.Warehouse.FetchByID(this.WarehouseID); }
			set { SetColumnValue("WarehouseID", value.WarehouseID); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varSaleID,string varIsbn,decimal? varSellingPrice,int? varAmount,string varBookType,double? varDiscount,string varWarehouseID)
		{
			Saledetail item = new Saledetail();
			
			item.SaleID = varSaleID;
			
			item.Isbn = varIsbn;
			
			item.SellingPrice = varSellingPrice;
			
			item.Amount = varAmount;
			
			item.BookType = varBookType;
			
			item.Discount = varDiscount;
			
			item.WarehouseID = varWarehouseID;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varId,string varSaleID,string varIsbn,decimal? varSellingPrice,int? varAmount,string varBookType,double? varDiscount,string varWarehouseID)
		{
			Saledetail item = new Saledetail();
			
				item.Id = varId;
			
				item.SaleID = varSaleID;
			
				item.Isbn = varIsbn;
			
				item.SellingPrice = varSellingPrice;
			
				item.Amount = varAmount;
			
				item.BookType = varBookType;
			
				item.Discount = varDiscount;
			
				item.WarehouseID = varWarehouseID;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn SaleIDColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn IsbnColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn SellingPriceColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn AmountColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn BookTypeColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn DiscountColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn WarehouseIDColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string SaleID = @"SaleID";
			 public static string Isbn = @"ISBN";
			 public static string SellingPrice = @"SellingPrice";
			 public static string Amount = @"Amount";
			 public static string BookType = @"BookType";
			 public static string Discount = @"Discount";
			 public static string WarehouseID = @"WarehouseID";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
